package com.opo5.logisticsmanagement.autotask;

import com.opo5.logisticsmanagement.common.ApplicationContextUtil;
import com.opo5.logisticsmanagement.common.AutoTaskUtil;
import com.opo5.logisticsmanagement.dao.MessageDao;
import com.opo5.logisticsmanagement.dao.VehicleInsuranceDao;
import com.opo5.logisticsmanagement.domain.VehicleInsurance;

import java.util.List;

/**
 * @Title: Task
 * @Author: lixin
 * @Date: 2022/07/11/11:35
 * @Description: 自动任务类
 */
public class Task {

    public VehicleInsuranceDao vehicleInsuranceDao;
    public MessageDao messageDao;

    public void getCarOverdue(){

        vehicleInsuranceDao = (VehicleInsuranceDao) ApplicationContextUtil.getBean("vehicleInsuranceDao");
        messageDao = (MessageDao) ApplicationContextUtil.getBean("messageDao");

        List<VehicleInsurance> vehicleInsurances =  vehicleInsuranceDao.selectList(null);

        vehicleInsurances.forEach(vehicleInsurance -> {

            String s = vehicleInsurance.getStartDateOfCommercialInsurance().split(",")[1];
            String s1 = vehicleInsurance.getStartDateOfCompulsoryInsurance().split(",")[1];

            if (AutoTaskUtil.CompareStringDate(s)<=0){
                messageDao.insert(AutoTaskUtil.getMessage(vehicleInsurance.getLicensePlate()+"商业保险过期了"));
            }
            if (AutoTaskUtil.CompareStringDate(s1)<=0){
                messageDao.insert(AutoTaskUtil.getMessage(vehicleInsurance.getLicensePlate()+"交强险过期了"));
            }
        });
    }

    public void getVolume(Integer i){
        System.out.println(Thread.currentThread().getName()+i);
    }

}
